package user

import (
	"context"
	v1 "qiyu-contact/api/user/v1"
	"qiyu-contact/internal/service"
)

func (u *UserControllerV1) Login(ctx context.Context, req *v1.LoginReq) (res *v1.LoginRes, err error) {
	tokenString, _ := service.Auth().LoginHandler(ctx)
	login, err := service.User().Login(ctx, req)
	if err != nil {
		return nil, err
	}
	res = &v1.LoginRes{
		Token: tokenString,
		User:  login.User,
	}
	return
}
func (u *UserControllerV1) Register(ctx context.Context, req *v1.RegisterReq) (res *v1.RegisterRes, err error) {
	register, err := service.User().Register(ctx, req)
	if err != nil {
		return nil, err
	}
	res = register
	return
}
func (u *UserControllerV1) FindUserAccount(ctx context.Context, req *v1.FindUserAccountReq) (res *v1.FindUserAccountRes, err error) {
	account, err := service.User().FindUserAccount(ctx, req)
	if err != nil {
		return nil, err
	}
	res = account
	return
}
func (u *UserControllerV1) GetUserFriend(ctx context.Context, req *v1.GetUserFriendReq) (res *v1.GetUserFriendRes, err error) {
	friend, err := service.User().FindUserFriend(ctx, req)
	if err != nil {
		return nil, err
	}
	res = friend
	return
}
func (u *UserControllerV1) GetUserDetail(ctx context.Context, req *v1.GetUserDetailReq) (res *v1.GetUserDetailRes, err error) {
	detail, err := service.User().GetUserDetail(ctx, req)
	if err != nil {
		return nil, err
	}
	res = detail
	return
}
